#include "StdAfx.h"
#include "PlayerController.h"
#include "PlayerControlLogic.h"
#include "EntityControl.h"
#include "PlayerControlElement.h"
#include "ControlContext.h"
#include "ControlStatus.h"



PlayerController::PlayerController(PlayerControlLogic* playerControlLogic)
	:playerControlLogic(playerControlLogic)
{
}


PlayerController::~PlayerController(void)
{
	//delete playerControlLogic;
}

bool PlayerController::isSpawningNeeded()
{
	return false;
}
bool PlayerController::apply(EntityControl* entity, const ControlContext& context)
{


	if(entity->isWaiting())
	{

		if(0<context.controlStatus.getBoundKeyValue("START_KEY"))
		{
			entity->play();
		}
	}

	if(entity->isPlaying())
	{







		////Move
		//Move::IMoveManager* move = context.controlStatus.getController();
		//Move::Quaternion oriMove = move->getOrientation(0);
		//Ogre::Quaternion ori = Ogre::Quaternion(oriMove.w, oriMove.x, oriMove.y, oriMove.z);
		Ogre::Quaternion ori = Ogre::Quaternion();

		//Move::Vector3 posMove = move->getPosition(0);
		//Ogre::Vector3 pos = Ogre::Vector3(posMove.x, posMove.y, posMove.z);

		Ogre::Vector3 currentPos = entity->getLocalPosition();
		int controllerX = context.controlStatus.getKeyValue(INPUT_POINTER_REL_X);
		int controllerY = context.controlStatus.getKeyValue(INPUT_POINTER_REL_Y);

		Ogre::Vector3 pos = Ogre::Vector3(currentPos.x+controllerX,currentPos.y+controllerY,0);




		//if(pos.x>30 || pos.x<-30 /*|| pos.y>50 || pos.y<-50*/)
		//{
		//	entity->getMasterBody()->getParentNode()->getParent()->yaw(Ogre::Radian((-1.0*pos.x)/10000.0));
		//	
		//	
		//}

		if(pos.x>50)
			pos.x=50;
		if(pos.x<-50)
			pos.x=-50;
		if(pos.y>50)
			pos.y=50;
		if(pos.y<-50)
			pos.y=-50;


		entity->setLocalOrientation(ori);
		entity->setLocalPosition(pos);


	}

	return true;

}



Ogre::String PlayerController::getType()
{
	return "PlayerController";
}